{include file='header'/}
<body>
<div class="weadmin-body">
    <form class="layui-form" action="javascript:;" onsubmit="return dosub(this)" method="post">
        <div class="layui-form-item">
            <label class="layui-form-label">轮播分类</label>
            <div class="layui-input-inline">
                <select  name="typeid" style="width:230px;" id="typeid">
                    <option value="0">无分类</option>
                    {foreach $types as $v}
                    <option value="{$v.tid}" {if($v.tid==$data.typeid)}selected{/if}>{$v.name}</option>
                    {/foreach}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                <a href="javascript:;" onclick="WeAdminShow('添加分类','{:url('cat_add')}','650','400')" class="ml-5">添加</a> |
                <a href="javascript:;" onclick="WeAdminShow('管理分类','{:url('cat_manage')}','650','500')">管理</a>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="we-red">*</span>标题名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="title" name="title" value="{$data.title}" lay-verify="required" autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" id="url" name="url" value="{$data.url}" autocomplete="off" class="layui-input" >
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">图片地址</label>
            <div class="layui-input-inline" style="width: 45%">
                <input type="text" name="image" value="{$data.image}" onmouseover="hui_img_preview('image',this.value)" onmouseout="layer.closeAll();" id="image" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-input-inline" style="width: 120px">
                <button type="button" class="layui-btn" id="test1" ><i class="layui-icon">&#xe67c;</i>上传图片</button>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-inline">
                <input type="text" id="listorder" name="listorder" value="{$data.listorder}" autocomplete="off" class="layui-input" >
            </div>
            <div class="layui-form-mid layui-word-aux">[从小到大排列]</div>
        </div>

        <div class="layui-form-item">
            <label for="status" class="layui-form-label">是否启用</label>
            <div class="layui-input-block" id="status">
                <input type="radio" name="status" value="1" title="启用" {if($data.status==1)}checked{/if}>
                <input type="radio" name="status" value="0" title="禁用" {if($data.status==0)}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <input type="hidden" name="id" value="{$data.id}">
            <input type="hidden" name="dosubmit" value="1">
            <button class="layui-btn"  lay-submit=""type="submit"   value="1" name="dosubmit">确定</button>
        </div>
    </form>
</div>

{include file='footer'/}

<script>
    layui.use(['form','upload'], function() {
        var form = layui.form,
            upload = layui.upload;
        form.render();
        form.verify({
            siteUrl:[
                /^http(.+)$/
                ,'站点根网址格式为：http://www.baidu.com'
            ]
        });
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: "{:url('upload/index')}"
            ,field:"Filedata"
            ,done: function(res){
                console.log(res.src)
                if(res.status==1){
                    $("#image").val(res.src);
                }
            }

        })
    });
    function dosub(obj) {
        if($("input[name='title']").val()==''){
            layer.msg('标题名称不能为空！');
            return false;
        }
        if($("input[name='url']").val()=='http://' || $("input[name='url']").val()==''){
            layer.msg('链接地址不能为空！');
            return false;
        }
        if($("input[name='image']").val()==''){
            layer.msg('请上传轮播图！');
            return false;
        }
        $.ajax({
            type: 'POST',
            url: '{:url('edit')}',
            data: $(obj).serialize(),
            dataType: "json",
            success: function (res) {
                if(res.status == 1){
                    layer.msg(res.msg, {
                        icon: 1,
                        time: 200
                    }, function(){
                        parent.location.reload();
                    });
                }else{
                    layer.msg(res.msg);
                }
            }
        });
        return false;
    }
</script>
</body>
</html>
